import request from '@/utils/request'

// 题目管理API
export default {
  // 分页查询题目列表
  getTableDataApi(searchModel) {
    return request({
      url: '/question/selectPageData',
      method: 'post',
      params: {
        page: searchModel.currentPage,
        size: searchModel.pageSize,
        categoryId: searchModel.categoryId,
        questionType: searchModel.questionType,
        difficultyLevel: searchModel.difficultyLevel,
        title: searchModel.title
      }
    })
  },

  // 新增/编辑题目
  updateAndSaveApi(question) {
    return request({
      url: '/question/updateAndSave',
      method: 'post',
      data: question
    })
  },

  // 删除题目
  delDataApi(id) {
    return request({
      url: `/question/delDataById/${id}`,
      method: 'delete'
    })
  },

  // 批量删除题目
  delDataByIdsApi(ids) {
    return request({
      url: '/question/delDataByIds',
      method: 'post',
      data: ids
    })
  },

  // 搜索题目
  searchQuestionsApi(keyword) {
    return request({
      url: '/question/searchQuestions',
      method: 'get',
      params: { keyword }
    })
  },

  // 获取随机题目
  getRandomQuestionApi() {
    return request({
      url: '/question/getRandomQuestion',
      method: 'get'
    })
  },

  // 根据分类获取题目
  getQuestionsByCategoryApi(categoryId) {
    return request({
      url: `/question/getQuestionsByCategory/${categoryId}`,
      method: 'get'
    })
  },

  // 根据难度获取题目
  getQuestionsByDifficultyApi(difficultyLevel) {
    return request({
      url: `/question/getQuestionsByDifficulty/${difficultyLevel}`,
      method: 'get'
    })
  },

  // 导出题目
  exportDataApi() {
    return request({
      url: '/question/exportOut',
      method: 'get',
      responseType: 'blob'
    })
  }
}
